package com.zz.framework.core.utils;

import android.text.TextUtils;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 *
 * Created by zanezhao on 2018/7/5 上午10:28.
 * @author: zanezhao
 * @version: V1.0
 */
public class IdsUtil {
    public static String toString(List<String> list) {
        return toString(list, ",");
    }

    public static String toString(List<String> list, String s) {
        if (TextUtils.isEmpty(s))
            s = ",";
        String str = "";
        if (list == null || list.size() == 0) {
            return str;
        }
        boolean isImages = false;
        for (String img : list) {
            if (!TextUtils.isEmpty(img)) {
                str += img + s;
                isImages = true;
            }
        }
        if (isImages) {
            str = str.substring(0, str.length() - s.length());
        }
        return str;
    }


    public static List<String> getList(String src) {
        return getList(src, ",", true);
    }

    /**
     *
     * @param src
     * @param split
     * @param isRepeat true 代表没有重复
     * @return
     */
    public static List<String> getList(String src, String split, boolean isRepeat) {
        if (src == null || "".equals(src)) {
            return new ArrayList<>();
        }
        if (TextUtils.isEmpty(split)) {
            split = ",";
        }
        List<String> list = (List<String>) Arrays.asList(src.split(split));
        if (list == null) return new ArrayList<>();
        if (!isRepeat) {
            return new ArrayList<String>(list);
        }
        List<String> listnew = new ArrayList<>();
        for (String str : list) {
            if (!TextUtils.isEmpty(str)) {
                boolean isAdd = false;
                for (String strnew : listnew) {
                    if (str.equals(strnew)) {
                        isAdd = true;
                        break;
                    }
                }
                if (!isAdd) {
                    listnew.add(str);
                }
            }
        }
        return listnew;
    }


}
